<template>
  <div class="invoi_wrap">
    <div class="invoi_mian">
      <div>
        <el-breadcrumb separator-class="el-icon-arrow-right">
          <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
          <el-breadcrumb-item v-if="!pathTo" :to="{ path: '/outfit' }"
            >特装</el-breadcrumb-item
          >
          <el-breadcrumb-item v-if="pathTo" :to="{ path: '/applyRecord' }"
            >报馆记录</el-breadcrumb-item
          >
          <el-breadcrumb-item>发票申请</el-breadcrumb-item>
        </el-breadcrumb>
      </div>
      <div class="invoi_query">
        <!-- <el-form
          ref="form"
          label-position="left"
          :model="queryform"
          label-width="100px"
        >
          <el-form-item label="查询展位号:">
            <el-input
              style="width: 192px"
              size="mini"
              v-model="queryform.name"
            ></el-input>
          </el-form-item>
        </el-form> -->
        <div class="invoi_query_list">
          <el-button type="primary" size="mini" @click="doInvoiceApply"
            >发票申请</el-button
          >
          <el-button type="danger" size="mini" @click="open = true"
            >发票抬头设置</el-button
          >
        </div>
      </div>
      <div>
        <el-table :data="tableData" style="width: 100%">
          <el-table-column type="index" width="50"></el-table-column>
          <el-table-column label="发票类型" align="center" prop="invoiceType">
            <template slot-scope="scope">
              <dict-tag
                :options="dict.type.invoice_type"
                :value="scope.row.invoiceType"
              />
            </template>
          </el-table-column>
          <el-table-column prop="exhibitionCompany" label="参展公司">
          </el-table-column>
          <el-table-column prop="exNumber" label="展馆号"> </el-table-column>
          <el-table-column prop="standNum" label="展位号"> </el-table-column>
          <el-table-column prop="standArea" label="展位面积"> </el-table-column>
          <el-table-column prop="companyName" label="公司名称">
          </el-table-column>
          <el-table-column prop="companyDutyNumber" label="公司税号">
          </el-table-column>

          <el-table-column prop="openingAccount" label="开户账号">
          </el-table-column>
          <el-table-column prop="receiveAddress" label="收件地址">
          </el-table-column>
          <el-table-column prop="receiverName" label="收件人">
          </el-table-column>
          <el-table-column prop="receiverTel" label="联系方式">
          </el-table-column>
          <!--          <el-table-column prop="checkStatus" label="发票审核状态">-->
          <!--            <template slot-scope="scope">-->
          <!--              <dict-tag-->
          <!--                :options="dict.type.audit_stat"-->
          <!--                :value="scope.row.checkStatus"-->
          <!--              />-->
          <!--            </template>-->
          <!--          </el-table-column>-->
          <el-table-column prop="invoiceStatus" label="发票状态">
            <template slot-scope="scope">
              <dict-tag
                :options="dict.type.invoice_stat"
                :value="scope.row.invoiceStatus"
              />
            </template>
          </el-table-column>
          <el-table-column prop="invoiceUrl" label="发票附件地址">
          </el-table-column>
          <el-table-column prop="applyTime" label="申请时间"> </el-table-column>
          <el-table-column label="操作">
            <template slot-scope="scope">
              <el-button v-if="scope.row.invoiceType == 2" @click="down(scope.row)" type="text">下载</el-button>
            </template>
          </el-table-column>
        </el-table>
        <pagination
          v-show="total > 0"
          :total="total"
          :page.sync="queryParams.pageNum"
          :limit.sync="queryParams.pageSize"
          @pagination="getlist"
        />
      </div>
    </div>

    <!-- 弹窗区域 -->
    <el-dialog
      title="申请"
      :visible.sync="dialogVisible"
      width="700px"
      :before-close="handleClose"
      :close-on-click-modal="false"
    >
      <el-form
        :model="ruleForm"
        :rules="rules"
        ref="ruleForm"
        inline
        size="mini"
        label-position="left"
        label-width="100px"
        class="demo-ruleForm"
      >
        <div class="dialog_text_list">
          <div class="dialog_shu"></div>
          <div class="dialog_text">发票信息 —— 开具发票所需信息</div>
        </div>
        <el-form-item label="订单号:" prop="orderNum">
          <el-select
                  style="width: 200px"
                  v-model="ruleForm.orderNum"
                  filterable
                  @change="chengorder"
                  placeholder="请选择"
          >
            <el-option
                    v-for="item in options"
                    :key="item.orderNum"
                    :label="item.orderNum"
                    :value="item.orderNum"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="申请开票金额:" prop="invoiceMoney">
          <el-input
                  style="width: 200px"
                  clearable
                  v-model="orderdata.userfeeTotal"
                  disabled
          ></el-input>
        </el-form-item>
        <el-form-item label="发票类型:" prop="invoiceType">
          <el-select
            style="width: 200px"
            v-model="ruleForm.invoiceType"
            placeholder="请选择发票类型"
          >
            <el-option
              v-for="dict in dict.type.invoice_type"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="展会名称:" prop="exhibitionName">
          <el-input
            style="width: 200px"
            disabled
            v-model="ruleForm.exhibitionName"
          ></el-input>
        </el-form-item>
        <el-form-item label="展馆号:" prop="exNumber">
          <el-select
            style="width: 200px"
            v-model="ruleForm.exNumber"
            filterable
            clearable
            @change="changeExNumber"
          >
            <el-option
              v-for="item in exNumber"
              :key="item"
              :label="item"
              :value="item"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="展位编号:" prop="standNum">
          <!-- <el-input v-model="ruleForm.standNum"></el-input> -->
          <el-autocomplete
            style="width: 200px"
            v-model="ruleForm.standNum"
            :fetch-suggestions="querySearchAsync"
            @select="handleSelect"
            value-key="standNum"
            clearable
          ></el-autocomplete>
        </el-form-item>
        <el-form-item label="公司税号:" prop="companyDutyNumber">
          <el-input
            style="width: 200px"
            clearable
            v-model="ruleForm.companyDutyNumber"
          ></el-input>
        </el-form-item>

        <el-form-item label="发票抬头:" prop="companyName">
          <el-input
            style="width: 200px"
            disabled
            v-model="ruleForm.companyName"
          ></el-input>
        </el-form-item>
        <!--        <el-form-item label="展位面积:" prop="standArea">-->
        <!--          <el-input   style="width:200px;" disabled v-model="ruleForm.standArea"></el-input>-->
        <!--        </el-form-item>-->
        <el-form-item label="开户行:" prop="openingBank">
          <el-input
            style="width: 200px"
            clearable
            v-model="ruleForm.openingBank"
          ></el-input>
        </el-form-item>
        <el-form-item label="开户账号:" prop="openingAccount">
          <el-input
            style="width: 200px"
            clearable
            v-model="ruleForm.openingAccount"
          ></el-input>
        </el-form-item>
        <el-form-item label="注册地址:" prop="regAddress">
          <el-input
            style="width: 200px"
            clearable
            v-model="ruleForm.regAddress"
          ></el-input>
        </el-form-item>
        <el-form-item label="注册电话:" prop="regPhone">
          <el-input
            style="width: 200px"
            clearable
            v-model="ruleForm.regPhone"
          ></el-input>
        </el-form-item>


<!--      <div v-if="orderdata.orderId">-->
<!--        <el-descriptions title="订单信息" border>-->
<!--    <el-descriptions-item label="订单编号">{{orderdata.orderNum}}</el-descriptions-item>-->
<!--    <el-descriptions-item label="下单时间">{{orderdata.orderTime}}</el-descriptions-item>-->
<!--    <el-descriptions-item label="订单金额">{{orderdata.orderAmount}}</el-descriptions-item>-->
<!--    <el-descriptions-item label="展会名称"> {{orderdata.exhibitionName}}</el-descriptions-item>-->
<!--     <el-descriptions-item label="参展公司名称"> {{orderdata.exhibitionCompany}}</el-descriptions-item>-->
<!--&lt;!&ndash;     <el-descriptions-item label="联系人姓名"> {{orderdata.linkName}}</el-descriptions-item>&ndash;&gt;-->
<!--&lt;!&ndash;     <el-descriptions-item label="联系人电话"> {{orderdata.linkPhone}}</el-descriptions-item>&ndash;&gt;-->
<!--</el-descriptions>-->
<!--      </div>-->


        <div class="dialog_text_list">
          <div class="dialog_shu"></div>
          <div class="dialog_text">
            联系方式 -- 用于发送发票文件，或有问题时取得联系
          </div>
        </div>
        <el-form-item
          v-if="ruleForm.invoiceType == 2"
          label="邮箱地址:"
          prop="email"
        >
          <el-input
            style="width: 200px"
            clearable
            v-model="ruleForm.email"
          ></el-input>
        </el-form-item>
        <el-form-item label="联系人:" prop="linkMan">
          <el-input
            style="width: 200px"
            clearable
            v-model="ruleForm.linkMan"
          ></el-input>
        </el-form-item>
        <el-form-item label="手机号码:" prop="linkPhone">
          <el-input
            style="width: 200px"
            clearable
            v-model="ruleForm.linkPhone"
          ></el-input>
        </el-form-item>

        <div v-if="ruleForm.invoiceType == 1">
          <div class="dialog_text_list">
            <div class="dialog_shu"></div>
            <div class="dialog_text">快递信息领取方式 : 到付</div>
          </div>
          <el-form-item label="收件地址:" prop="receiveAddress">
            <el-input
              style="width: 200px"
              clearable
              v-model="ruleForm.receiveAddress"
            ></el-input>
          </el-form-item>
          <el-form-item label="收件人姓名:">
            <el-input
              style="width: 200px"
              clearable
              v-model="ruleForm.receiverName"
            ></el-input>
          </el-form-item>
          <el-form-item label="收件人电话:" prop="receiverTel">
            <el-input
              style="width: 200px"
              clearable
              v-model="ruleForm.receiverTel"
            ></el-input>
          </el-form-item>

          <!--          <el-form-item label="发票附件地址:" prop="invoiceUrl">-->
          <!--            <el-input   style="width:200px;" clearable v-model="ruleForm.invoiceUrl"></el-input>-->
          <!--          </el-form-item>-->
          <!--          <el-form-item label="发票状态:" prop="invoiceStatus">-->
          <!--            <el-select-->
          <!--              style="width:200px;"-->
          <!--              v-model="ruleForm.invoiceStatus"-->
          <!--              clearable-->
          <!--              placeholder="请选择发票状态"-->
          <!--            >-->
          <!--              &lt;!&ndash; <el-option label="未开票" value="0"></el-option>-->
          <!--              <el-option label="已开票" value="1"></el-option> &ndash;&gt;-->
          <!--              <el-option-->
          <!--                v-for="dict in dict.type.invoice_stat"-->
          <!--                :key="dict.value"-->
          <!--                :label="dict.label"-->
          <!--                :value="dict.value"-->
          <!--              />-->
          <!--            </el-select>-->
          <!--          </el-form-item>-->
        </div>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="hanldadd">确 定</el-button>
      </span>
    </el-dialog>
    <!-- 添加或修改发票抬头对话框 -->
    <el-dialog
      title="发票抬头库"
      :visible.sync="open"
      width="1000px"
      @close="fpclose"
      :show-close="true"
      :close-on-click-modal="false"
    >
      <el-button
        type="danger"
        plain
        icon="el-icon-plus"
        size="mini"
        @click="handleAdd"
        >新增</el-button
      >
      <el-table
        v-loading="loading"
        :data="invoice_headerList"
        @selection-change="handleSelectionChange"
        ref="tb"
      >
        <el-table-column type="selection" width="55" align="center" />
        <el-table-column label="序号" align="center" prop="headId" />
        <!--        <el-table-column label="用户id" align="center" prop="userId" />-->
        <!--        <el-table-column label="展会id" align="center" prop="exhibitionId" />-->
        <el-table-column label="发票抬头" align="center" prop="invoiceHeader" />
        <el-table-column label="税号" align="center" prop="taxNumber" />
        <el-table-column label="注册地址" align="center" prop="regAddress" />
        <el-table-column label="注册电话" align="center" prop="regPhone" />
        <el-table-column label="开户行账号" align="center" prop="accountBank" />
        <el-table-column
          label="开户行地址"
          align="center"
          prop="accountNumber"
        />
        <el-table-column
          label="操作"
          align="center"
          class-name="small-padding fixed-width"
        >
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="text"
              icon="el-icon-edit"
              @click="handleUpdate(scope.row)"
              >修改</el-button
            >
            <el-button
              size="mini"
              type="text"
              icon="el-icon-delete"
              @click="handleDelete(scope.row)"
              >删除</el-button
            >
          </template>
        </el-table-column>
      </el-table>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="chooseHeader">确定</el-button>
      </div>
      <el-dialog
        :title="title"
        :visible.sync="innerVisible"
        append-to-body
        :close-on-click-modal="false"
      >
        <el-form
          ref="form"
          :model="form"
          :rules="headerRules"
          label-width="80px"
        >
          <!--        <el-form-item label="用户id" prop="userId">-->
          <!--          <el-input v-model="form.userId" placeholder="请输入用户id" />-->
          <!--        </el-form-item>-->
          <!--        <el-form-item label="展会id" prop="exhibitionId">-->
          <!--          <el-input v-model="form.exhibitionId" placeholder="请输入展会id" />-->
          <!--        </el-form-item>-->
          <el-form-item label="发票抬头" prop="invoiceHeader">
            <el-input
              v-model="form.invoiceHeader"
              placeholder="请输入发票抬头"
            />
          </el-form-item>
          <el-form-item label="税号" prop="taxNumber">
            <el-input v-model="form.taxNumber" placeholder="请输入税号" />
          </el-form-item>
          <el-form-item label="注册地址" prop="regAddress">
            <el-input v-model="form.regAddress" placeholder="请输入注册地址" />
          </el-form-item>
          <el-form-item label="注册电话" prop="regPhone">
            <el-input v-model="form.regPhone" placeholder="请输入注册电话" />
          </el-form-item>
          <el-form-item label="开户行" prop="accountBank">
            <el-input v-model="form.accountBank" placeholder="请输入开户行" />
          </el-form-item>
          <el-form-item label="开户行账号" prop="accountNumber">
            <el-input
              v-model="form.accountNumber"
              placeholder="请输入开户行账号"
            />
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button type="primary" @click="submitForm">确 定</el-button>
          <el-button @click="cancel">取 消</el-button>
        </div>
      </el-dialog>
    </el-dialog>
  </div>
</template>
<script>
import {
  stand_infoid,
  stand_infolist,
  getExhibition_info,
  getStandInfo,
  verifyHasApply,
} from "@/api/outfit/drawingadd.js";
import{getlist,getdeilts} from "@/api/order.js"
import { invoice_apply, invoice_list } from "../../api/outfit/invoicel.js";
import {
  listInvoice_header,
  getInvoice_header,
  delInvoice_header,
  addInvoice_header,
  updateInvoice_header,
} from "../../api/outfit/invoicel.js";
import { stand_info } from "@/api/outfit/drawingadd.js";
import { getToken, setToken } from "@/utils/auth";
import email from "../../components/login/email";
export default {
  dicts: ["invoice_stat", "audit_stat", "invoice_type"],
  data() {
    return {
      orderdata:{},
      exhibition: {},
      queryform: {},
      ruleForm: {},
      tableData: [],
      headerForm: {},
      title: "",
      dialogVisible: false,
      test: "",
      open: true,
      headerVisible: false,
      innerVisible: false,
      loading: false,
      rules: {
        invoiceType: [
          { required: true, message: "请选择发票类型", trigger: "change" },
        ],
        companyName: [
          { required: true, message: "请输入公司名称", trigger: "blur" },
        ],
        companyDutyNumber: [
          { required: true, message: "请输入公司税号", trigger: "blur" },
        ],
        exhibitionCompany: [
          {
            required: true,
            message: "请输入参展公司/展位名称",
            trigger: "blur",
          },
        ],
        email: [
          { required: true, message: "请输入邮箱地址", trigger: "blur" },
          {
            type: "email",
            message: "请输入正确的邮箱地址",
            trigger: ["blur", "change"],
          },
        ],
        linkMan: [
          { required: true, message: "请输入联系人名称", trigger: "blur" },
        ],
        linkPhone: [
          { required: true, message: "请输入联系人电话", trigger: "blur" },
          {
            pattern: /^(?:(?:\+|00)86)?1[3-9]\d{9}$/,
            message: "请输入正确的手机号",
            trigger: "blur",
          },
        ],
        exNumber: [
          { required: true, message: "请输入展馆号", trigger: "blur" },
        ],
        exhibitionName: [
          { required: true, message: "请输入展会名称", trigger: "blur" },
        ],
        standNum: [
          { required: true, message: "请输入展位编号", trigger: "blur" },
        ],
        openingAccount: [
          { required: true, message: "请输入开户账号", trigger: "blur" },
        ],
        openingBank: [
          { required: true, message: "请输入开户行", trigger: "blur" },
        ],
        receiveAddress: [
          { required: true, message: "请输入收件地址", trigger: "blur" },
        ],
        receiverName: [
          { required: true, message: "请输入收件人账号", trigger: "blur" },
        ],
        receiverTel: [
          { required: true, message: "请输入收件人电话", trigger: "blur" },
          {
            pattern: /^(?:(?:\+|00)86)?1[3-9]\d{9}$/,
            message: "请输入正确的手机号",
            trigger: "blur",
          },
        ],
        regAddress: [
          { required: true, message: "请输入注册地址", trigger: "blur" },
        ],
        regPhone: [
          { required: true, message: "请输入注册电话", trigger: "blur" },
        ],
         orderNum: [
          { required: true, message: "订单号不能为空", trigger: "change" },
        ],
      },
      invoiceHeader: {},
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        exhibitionId: null,
        openInvoice: null,
      },
      headerParams: {
        pageNum: 1,
        pageSize: 10,
        userId: null,
      },
      exNumber: [],
      stan: {},
      datafrom: {},
      form: {},
      total: 0,
      defaultType: 1,
      invoice_headerList: [],
      headerRules: {
        invoiceHeader: [
          { required: true, message: "发票抬头不能为空", trigger: "blur" },
        ],
        taxNumber: [
          { required: true, message: "税号不能为空", trigger: "blur" },
        ],
        regAddress: [
          { required: true, message: "注册地址不能为空", trigger: "blur" },
        ],
        regPhone: [
          { required: true, message: "注册电话不能为空", trigger: "blur" },
        ],
        accountBank: [
          { required: true, message: "开户行不能为空", trigger: "blur" },
        ],
        accountNumber: [
          { required: true, message: "开户行地址不能为空", trigger: "blur" },
        ],
        createTime: [
          { required: true, message: "创建时间不能为空", trigger: "blur" },
        ],
       
      },
      userId: null,
      exhibitionId: null,
      standId: null,
      pathTo: false,
      options:[]
    };
  },
  created() {
    this.standId = this.$route.query.standId;
    this.pathTo = this.$route.query.to;
    this.ruleForm.companyName = getToken("username");
    let user = JSON.parse(getToken("user"));
    let exhibition = JSON.parse(getToken("exhibition"));
    if (user) {
      this.userId = user.userId;
    }
    if (exhibition) {
      this.exhibitionId = exhibition.id;
    }
    this.getinputdata();
    this.getlist();
    this.getInvoiceList();
  },
  activated() {
    this.standId = this.$route.query.standId;
    this.pathTo = this.$route.query.to;
    this.ruleForm.companyName = getToken("username");
    let user = JSON.parse(getToken("user"));
    let exhibition = JSON.parse(getToken("exhibition"));
    if (user) {
      this.userId = user.userId;
    }
    if (exhibition) {
      this.exhibitionId = exhibition.id;
    }
    this.getinputdata();
    this.getlist();
    this.getInvoiceList();
  },
  methods: {
    // 发票抬头库的关闭回调
    fpclose() {
      this.open = false;
    },
    down(row) {
      // window.open(row.invoiceUrl)
      // document
      // this.downloadByBlob(row.invoiceUrl)
      let imgurl = row.invoiceUrl;
      if (imgurl) {
        let link = document.createElement("a");

        fetch(imgurl)
          .then((res) => res.blob())
          .then((blob) => {
            link.href = URL.createObjectURL(blob);

            link.download = "pic";

            link.id = "Adownload";

            document.body.appendChild(link);

            link.click();

            document.getElementById("Adownload").remove();
          });
      } else {
        this.$message({
          showClose: true,
          message: "请耐心等候，发票会在三十个工作日内上传！",
          type: "error",
        });
      }
    },

    // 获取列表数据
    getlist() {
      this.queryParams.exhibitionId = this.exhibition.id;
      this.queryParams.exhibitionCompany = getToken("username");
      this.queryParams.openInvoice = 0;
      invoice_list(this.queryParams).then((res) => {
        if (res.code == 200) {
          this.total = res.total;
          this.tableData = res.rows;
        }
      });
      let form = {
        exhibitionName: this.exhibition.exhibitionName,
        userId: JSON.parse(getToken("user")).userId,
        checkStatus: 1
      }
      getlist(form).then(res=>{
        console.log(res);
        this.options = res.rows
      })
    },
    resetInvoice() {
      this.ruleForm = {
        id: null,
        orderNum: null,
        exhibitionName: null,
        exhibitionCompany: null,
        standNum: null,
        exNumber: null,
        invoiceType: null,
        standArea: null,
        companyName: null,
        companyDutyNumber: null,
        openingBank: null,
        openingAccount: null,
        receiveAddress: null,
        receiverName: null,
        receiverTel: null,
        checkStatus: 0,
        invoiceStatus: 0,
        invoiceUrl: null,
        applyTime: null,
        deleteFlag: null,
        regAddress: null,
        regPhone: null,
        standId: null,
        invoiceMoney: null,
      };
      this.resetForm("ruleForm");
    },
    doInvoiceApply() {
      this.open = true;
    },
    getInvoiceList() {
      this.loading = true;
      this.headerParams.userId = this.userId;
      listInvoice_header(this.headerParams).then((response) => {
        this.invoice_headerList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    handleSelectionChange(selection) {
      this.invoiceHeader = selection[0];
      if (selection.length > 1) {
        this.$refs.tb.clearSelection();
        this.$refs.tb.toggleRowSelection(selection.pop());
      }
    },
    chooseHeader() {
      console.log(this.invoiceHeader);
      if (!this.invoiceHeader.headId) {
        return this.$message.error("请选择抬头库");
      } else {
        this.open = false;
        this.resetInvoice();
        this.ruleForm.invoiceType = "1";
        // this.ruleForm.receiveAddress = null;
        // this.ruleForm.receiverName = null;
        // this.ruleForm.receiverTel = null
        if (this.standId) {
          this.hanldquery(this.standId);
        }
        if (this.invoiceHeader.invoiceHeader)
          this.ruleForm.companyName = this.invoiceHeader.invoiceHeader;
        if (this.invoiceHeader.taxNumber)
          this.ruleForm.companyDutyNumber = this.invoiceHeader.taxNumber;
        if (this.invoiceHeader.regAddress)
          this.ruleForm.regAddress = this.invoiceHeader.regAddress;
        if (this.invoiceHeader.regPhone)
          this.ruleForm.regPhone = this.invoiceHeader.regPhone;
        if (this.invoiceHeader.accountBank)
          this.ruleForm.openingBank = this.invoiceHeader.accountBank;
        if (this.invoiceHeader.accountNumber)
          this.ruleForm.openingAccount = this.invoiceHeader.accountNumber;
        if (this.invoiceHeader.linkMan)
          this.ruleForm.linkMan = this.invoiceHeader.linkMan;
        if (this.invoiceHeader.linkPhone)
          this.ruleForm.linkPhone = this.invoiceHeader.linkPhone;
        if (this.invoiceHeader.email)
          this.ruleForm.email = this.invoiceHeader.email;
        this.dialogVisible = true;
      }
    },
    handleClose() {
      this.$refs.ruleForm.resetFields();
      this.dialogVisible = false;
    },
    hanldadd() {
      this.ruleForm.checkStatus = 0;
      this.ruleForm.deleteFlag = 0;
      this.ruleForm.standId = this.stan.id;
      this.ruleForm.applyTime = new Date();
      this.ruleForm.exhibitionCompany = getToken("username");
      this.$refs.ruleForm.validate((valid) => {
        if (valid) {
          invoice_apply(this.ruleForm).then((res) => {
            if (res.code == 200) {
              this.$message.success("操作成功");
              if (this.stan.stage < 4) {
                let form = {
                  id: this.stan.id,
                  stage: 4,
                };
                stand_info(form);
              }
              this.handleClose();
              this.getlist();
            }
          });
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
    reset() {
      this.form = {
        headId: null,
        userId: null,
        exhibitionId: null,
        invoiceHeader: null,
        taxNumber: null,
        regAddress: null,
        regPhone: null,
        accountBank: null,
        accountNumber: null,
        createTime: null,
      };
      this.resetForm("form");
    },
    cancel() {
      this.innerVisible = false;
      this.reset();
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const headIds = row.headId;
      this.$message
        .confirm('是否确认删除发票抬头编号为"' + headIds + '"的数据项？')
        .then(function () {
          return delInvoice_header(headIds);
        })
        .then(() => {
          this.getList();
          this.$message.success("删除成功");
        })
        .catch(() => {});
    },
    // 获取远程搜索数据
    getinputdata() {
      this.exhibition = JSON.parse(getToken("exhibition"));
      this.endTime = this.switchTimeFormat(this.exhibition.endTime2);
      this.datafrom.exhibitionId = this.exhibition.id;
      if (this.exhibition.exNumber != null) {
        this.exNumber = this.exhibition.exNumber.split(";");
      }
      this.getStandInfo();
    },
    switchTimeFormat(time) {
      const dateTime = new Date(time);
      const year = dateTime.getFullYear();
      const month = dateTime.getMonth() + 1;
      const date = dateTime.getDate();
      const hour = dateTime.getHours() + 17;
      const minute = dateTime.getMinutes();
      const second = dateTime.getSeconds();
      return `${year}-${this.addZero(month)}-${this.addZero(
        date
      )} ${this.addZero(hour)}:${this.addZero(minute)}:${this.addZero(second)}`;
    },
    addZero(v) {
      return v < 10 ? "0" + v : v;
    },
    changeExNumber() {
      this.datafrom.exNumber = this.ruleForm.exNumber;
      this.ruleForm.name = "";
      this.test = "";
      this.getStandInfo();
    },
    getStandInfo() {
      stand_infolist(this.datafrom).then((res) => {
        if (res.code == 200) {
          this.restaurants = res.rows;
        }
      });
    },
    handleSelect(val) {
      var standId = val.id;
      this.hanldquery(standId);
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.innerVisible = true;
      this.title = "添加发票抬头";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const headId = row.headId;
      getInvoice_header(headId).then((response) => {
        this.form = response.data;
        this.innerVisible = true;
        this.title = "修改发票抬头";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.form.userId = this.userId;
      this.form.exhibitionId = this.exhibitionId;
      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (this.form.headId != null) {
            updateInvoice_header(this.form).then((response) => {
              this.$message.success("修改成功");
              this.innerVisible = false;
              this.getInvoiceList();
            });
          } else {
            addInvoice_header(this.form).then((response) => {
              this.$message.success("新增成功");
              this.innerVisible = false;
              this.getInvoiceList();
            });
          }
        }
      });
    },
    hanldquery(standId) {
      getStandInfo(standId).then((res) => {
        if (res.code == 200) {
          if (res.total == 0) {
            return this.$message.error("请输入有效的展位信息");
          } else {
            this.stan = res.data;
            console.log(this.stan);
            // verifyHasApply(standId).then((res) => {
            //   if (res.code == 200) {
            //     setToken("stanId", this.stan.id);
            //     setToken("stan", null);
            //   }
            // });
          }
          this.ruleForm.standNum = res.data.standNum;
          this.ruleForm.exNumber = res.data.exNumber;
          this.ruleForm.standArea = res.data.standArea;
          this.ruleForm.exhibitionCompany = res.data.exhibitionCompany;
          this.ruleForm.exhibitionName = res.data.exhibitionName;
        }
      });
    },
    // 数据进行匹配
    querySearchAsync(queryString, cb) {
      var restaurants = this.restaurants;
      var results = queryString
        ? restaurants.filter(this.createStateFilter(queryString))
        : restaurants;
      cb(results);
    },
    createStateFilter(queryString) {
      return (state) => {
        return state.standNum.indexOf(queryString) >= 0;
      };
    },
    chengorder(row){
      getdeilts(row).then(res=>{
        console.log(res);
        this.orderdata = res.data
        this.ruleForm.invoiceMoney = res.data.userfeeTotal;
        this.hanldquery(res.data.standNum)
      })
    }
  },
};
</script>
<style scoped>
.invoi_wrap {
  background-color: #f2f2f2;
  padding: 50px;
}
.invoi_mian {
  width: 1600px;
  background-color: #fff;
  padding: 10px;
  margin: auto;
}
.invoi_query {
  display: flex;
  justify-content: space-between;
}
.invoi_query_list {
  border-bottom: 1px solid #f2f2f2;
}
/deep/.el-table th.el-table__cell {
  background-color: #e4fafa !important;
  text-align: center !important;
}
/deep/.el-table td.el-table__cell,
.el-table th.el-table__cell.is-leaf {
  text-align: center !important;
}
.dialog_text_list {
  display: flex;
  margin-bottom: 10px;
}
.dialog_shu {
  width: 3px;
  height: 20px;
  background-color: #e6a23c;
}
.dialog_text {
  color: #666;
  margin-left: 10px;
  font-size: 14px;
}
</style>